package ca.nfb.media.nfbPlayer.views
{
	import ca.turbulent.media.Pyro;
	import ca.turbulent.media.events.StatusUpdateEvent;
	
	import flash.events.Event;
	import flash.events.FullScreenEvent;
	import flash.filters.*;
	
	public class PlayOverlay extends NFBPlayerView
	{
		public function PlayOverlay()
		{
			super();
			this.player.addEventListener(StatusUpdateEvent.STATUS_UPDATE, pyroStatusChanged, false, 0, true);
		}

		override protected function addedToStage(evt:Event):void 
		{ 
			registerStageEvents();	
			this.mouseEnabled = false;
			this.mouseChildren = false;
			
			this.visible = false;
			this.x = stage.stageWidth/2;
			this.y = (stage.stageHeight-core.controllerHeight)/2;
			this.filters = [new DropShadowFilter(2, 45, 0, .6, 5, 5)];
		}
		
		
		private function pyroStatusChanged(evt:Event):void
		{
			if (player.status == Pyro.STATUS_PAUSED)
			{
				switch(core.currentState)
				{
					case NFBPlayer.SHARING_STATE:
					case NFBPlayer.END_PLAYLIST_STATE:
					case NFBPlayer.MORE_INFOS_STATE:
					case NFBPlayer.OPTIONS_STATE:
					break;
					
					case NFBPlayer.DEFAULT_STATE:
					default:
					this.visible = true;		
					break;
				}  
				
			}
			else
			{
				this.visible = false;
			}
			
			if (core.currentState == NFBPlayer.PREVIEW_IMAGE_STATE && (core.showEmbeddedWelcome || core.embeddedMode))
				this.visible = false;
		}
		
		override protected function coreStateUpdated(evt:Event=null):void 
		{
			
		}
		
		override protected function fullscreenHandler(evt:FullScreenEvent):void
		{
			if (evt.fullScreen)
				this.scaleX = this.scaleY = 2;
			else
				this.scaleX = this.scaleY = 1;
					
			this.x = stage.stageWidth/2;
			this.y = (stage.stageHeight-core.controllerHeight)/2;
			
		}
		
		override protected function stageResized(evt:Event=null):void
		{
			this.x = stage.stageWidth/2;
			this.y = (stage.stageHeight-core.controllerHeight)/2;
		}
	}
}